package com.ticket.controller;

import com.ticket.entity.*;
import com.ticket.service.*;
import com.ticket.service.impl.*;
import com.ticket.util.Page;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.UnsupportedEncodingException;
import java.util.List;

/**
 * @author XuGuoZhi
 * @version 8.0
 * @description TODO 后端系统管理控制器
 * @date 2023/10/2
 */
public class BackEndController {

    static{

    }
    DramaService dramaService = new DramaServiceImpl();
    MusicService musicService = new MusicServiceImpl();
    SportsService sportsService = new SportsServiceImpl();
    DanceService danceService = new DanceServiceImpl();
    CrosStalkService crosStalkService = new CrosStalkServiceImpl();
    CinemaService cinemaService=new CinemaServiceImpl();
    MovieService movieService=new MovieServiceImpl();

    public Object selPageCinema(HttpServletRequest request, HttpServletResponse response) {
        try {
            request.setCharacterEncoding("UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        response.setContentType("charset=UTF-8;type=text/json;");
        HttpSession session= request.getSession();
        String cinemaName=request.getParameter("cinema_name");
        String pageIndex=request.getParameter("pageIndex");
        Page<Cinema> cinemaPage = new Page<>();
        if(pageIndex!=null){
            cinemaPage.setCurrPageNo(Integer.parseInt(pageIndex));
        }
        cinemaPage = cinemaService.selPageCinema(cinemaPage,cinemaName);
        if(cinemaPage.getDataList() != null){
            session.setAttribute("cinemaList",cinemaPage.getDataList());
            session.setAttribute("cinemaPage",cinemaPage);
            session.setAttribute("cinema_name",cinemaName);
            return "redirect:/back-end-jsp/articletype-list.jsp";
        }else{
            return "redirect:/back-end-jsp/welcome.jsp";
        }
    }
    /**
    * @author TanWenJie
    * @description TODO 演出活动话剧管理查询
    * @date 2023/10/7 11:05
     * @update 2023/10/12 15:46 XuGuoZhi
     * @param request
     * @param response
    * @return java.lang.Object
    */
    public Object selDrama(HttpServletRequest request, HttpServletResponse response){
        try {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("charset=UTF-8;type=text/json;");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        HttpSession session = request.getSession();
        String activityName=request.getParameter("activityName");
        Drama drama = new Drama();
        drama.setActivityName(activityName);
        String pageIndex=request.getParameter("pageIndex");//获取当前页面
        Page<Drama> page = new Page<>(5,1);
        if (pageIndex != null) {
            page.setCurrPageNo(Integer.parseInt(pageIndex));
        }
        Page<Drama> dramaPage = dramaService.selDramaPage(page,drama);
        if(dramaPage.getDataList()!=null){
            System.out.println(dramaPage.getDataList());
            session.setAttribute("activityName",activityName);
            session.setAttribute("page", dramaPage);
            session.setAttribute("listDramalist",dramaPage.getDataList());
            return "redirect:/back-end-jsp/drama-manage.jsp";
        }
        else{
            return "redirect:/back-end-jsp/welcome.jsp";
        }

    }


    /**
     * @author TanWenJie
     * @description TODO 演出活动音乐管理查询
     * @date 2023/10/7 11:05
     * @param request
     * @param response
     * @return java.lang.Object
     */
    public Object selMusic(HttpServletRequest request, HttpServletResponse response){
        try {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("charset=UTF-8;type=text/json;");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        HttpSession session = request.getSession();
        String activityName=request.getParameter("activityName");
        Drama drama = new Drama();
        drama.setActivityName(activityName);
        String pageIndex=request.getParameter("pageIndex");//获取当前页面
        Page<Drama> page = new Page<>(5,1);
        if (pageIndex != null) {
            page.setCurrPageNo(Integer.parseInt(pageIndex));
        }
        Page<Drama> dramaPage = musicService.selMusic(page,drama);
        if(dramaPage.getDataList()!=null){
            System.out.println(dramaPage.getDataList());
            session.setAttribute("activityName",activityName);
            session.setAttribute("page", dramaPage);
            session.setAttribute("listMusicList",dramaPage.getDataList());
            return "redirect:/back-end-jsp/music-manage.jsp";
        }
        else{
            return "redirect:/back-end-jsp/welcome.jsp";
        }
    }
    /**
     * @author TanWenJie
     * @description TODO 体育赛事管理查询
     * @date 2023/10/7 11:05
     * @param request
     * @param response
     * @return java.lang.Object
     */
    public Object selSports(HttpServletRequest request, HttpServletResponse response){
        try {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("charset=UTF-8;type=text/json;");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        HttpSession session = request.getSession();
        String contestName=request.getParameter("contestName");
        Contest contest = new Contest();
        contest.setContestName(contestName);
        String pageIndex=request.getParameter("pageIndex");//获取当前页面
        Page<Contest> page = new Page<>(5,1);
        if (pageIndex != null) {
            page.setCurrPageNo(Integer.parseInt(pageIndex));
        }
        Page<Contest> contestPage = sportsService.selSports(page,contest);
        if(contestPage.getDataList()!=null){
            System.out.println(contestPage.getDataList());
            session.setAttribute("contestName",contestName);
            session.setAttribute("page", contestPage);
            session.setAttribute("listContestList",contestPage.getDataList());
            return "redirect:/back-end-jsp/sports-manage.jsp";
        }
        else{
            return "redirect:/back-end-jsp/welcome.jsp";
        }
    }

    /**
     * @author TanWenJie
     * @description TODO 舞蹈管理查询
     * @date 2023/10/7 11:05
     * @param request
     * @param response
     * @return java.lang.Object
     */
    public Object selDance(HttpServletRequest request, HttpServletResponse response){
        try {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("charset=UTF-8;type=text/json;");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        HttpSession session = request.getSession();
        String activityName=request.getParameter("activityName");
        Drama drama = new Drama();
        drama.setActivityName(activityName);
        String pageIndex=request.getParameter("pageIndex");//获取当前页面
        Page<Drama> page = new Page<>(5,1);
        if (pageIndex != null) {
            page.setCurrPageNo(Integer.parseInt(pageIndex));
        }
        Page<Drama> dramaPage = danceService.selDance(page,drama);
        if(dramaPage.getDataList()!=null){
            System.out.println(dramaPage.getDataList());
            session.setAttribute("activityName",activityName);
            session.setAttribute("page", dramaPage);
            session.setAttribute("listDanceList",dramaPage.getDataList());
            return "redirect:/back-end-jsp/dance-manage.jsp";
        }
        else{
            return "redirect:/back-end-jsp/welcome.jsp";
        }
    }
    /**
     * @author TanWenJie
     * @description TODO 曲苑杂坛管理查询
     * @date 2023/10/7 11:05
     * @param request
     * @param response
     * @return java.lang.Object
     */
    public Object selCrosStalk(HttpServletRequest request, HttpServletResponse response){
        try {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("charset=UTF-8;type=text/json;");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        HttpSession session = request.getSession();
        String activityName=request.getParameter("activityName");
        Drama drama = new Drama();
        drama.setActivityName(activityName);
        String pageIndex=request.getParameter("pageIndex");//获取当前页面
        Page<Drama> page = new Page<>(5,1);
        if (pageIndex != null) {
            page.setCurrPageNo(Integer.parseInt(pageIndex));
        }

        Page<Drama> dramaPage = crosStalkService.selCrosStalk(page,drama);
        if(dramaPage.getDataList()!=null){
            System.out.println(dramaPage.getDataList());
            session.setAttribute("activityName",activityName);
            session.setAttribute("page", dramaPage);
            session.setAttribute("listCorsList",dramaPage.getDataList());
            return "redirect:/back-end-jsp/quyuanzatan-manage.jsp";
        }
        else{
            return "redirect:/back-end-jsp/welcome.jsp";
        }
    }

    /**
     * @description TODO 后端电影分页查询
     * @author XuGuoZhi
     * @date  9:39
      * @param request
    * @param response
     * @return java.lang.Object
     */
    public Object selPageMovie(HttpServletRequest request,HttpServletResponse response){
        try {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("charset=UTF-8;type=text/json;");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        HttpSession session = request.getSession();
        String pageIndex=request.getParameter("pageIndex");
        String movieCnName=request.getParameter("movieCnName");
        Page<Movie> moviePage =new Page<>(5,1);
        if(pageIndex!=null){
            moviePage.setCurrPageNo(Integer.parseInt(pageIndex));
        }
        moviePage=movieService.moviePageAndMovieNameSel(moviePage,movieCnName);
        if(moviePage!=null){
            session.setAttribute("movieCnName",movieCnName);
            session.setAttribute("movieList",moviePage.getDataList());
            return "redirect:/back-end-jsp/movie.jsp";
        }else{
            return "redirect:/back-end-jsp/welcome.jsp";
        }

    }
}
